#include("../../comm/ListHead.html")
<div id="main" style="width:100%;margin: 10px;">
    <div style="text-align:center">
        <form class="layui-form">
            <div class="layui-form-item">
                <input type="hidden" id="user_role" value='#(myrolestr)'>
                <input type="hidden" id="role_data" value='#(rolestr)'>
                <input type="hidden" id="emp_id" value='#(empid)'>

                <div id="trans_div" style="width:500px;margin:0 auto;text-align:left"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-btn-container2" style="margin:10px">
                    <button type="button" class="layui-btn layui-btn-sm btn-change-13" data-type="getData">保存</button>
                    <button type="button" class="layui-btn layui-btn-sm " data-type="reload">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<SCRIPT LANGUAGE="JavaScript">
    <!--
    var $ = layui.$;
    var user_role = JSON.parse($("#user_role").val());
    var role_data = JSON.parse($("#role_data").val());
    var emp_id = layui.$("#emp_id").val();

    layui.use(['transfer', 'layer', 'util'], function () {
        var transfer = layui.transfer;
        var layer = layui.layer;
        //渲染
        transfer.render({
            elem: '#trans_div'  //绑定元素
            , data: role_data
            , id: 'trans_1' //定义索引
            , title: ['未选角色', '已选角色'] //定义索引
            , text: {
                none: '未选择任何角色' //没有数据时的文案
                , searchNone: '无匹配角色' //搜索无匹配数据时的文案
            }
            , value: user_role
            , showSearch: false
            , width: 200
            , height: 320
        });


        layui.util.event("data-type", {
            getData: function () {
                var relestr = transfer.getData('trans_1'); //获取右侧数据
                var index = layer.load(1);
                layui.$.ajax({
                    type: 'POST',
                    url: "SetUserRoleApi",
                    data: {emp_id: emp_id, role_str: JSON.stringify(relestr)},
                    success: function (results) {
                        if (results.code == 0) {
                            layer.alert(results.msg, {offset: '100px'}, function (index) {
                                top.layer.closeAll();
                            });
                        } else {
                            layer.close(index);
                            layer.msg(results.msg);
                        }
                        return false;
                    },
                    error: function (return_data) {
                        return false;
                    },
                    dataType: "json"
                });
            }
            , reload: function () {
                transfer.reload('trans_1', {
                    value: user_role
                })
            }
        });
    });
    //-->
</SCRIPT>
</body>
</html>